package com.wejoy.video.middle.station.admin.controller.alarm;

import com.wejoy.video.middle.station.admin.controller.BaseController;
import com.wejoy.video.middle.station.admin.util.CurrentUserUtils;
import com.wejoy.video.middle.station.data.domain.PageResult;
import com.wejoy.video.middle.station.data.domain.alarm.ScreenUserCarmeraConfigTime;
import com.wejoy.video.middle.station.data.domain.system.SysUser;
import com.wejoy.video.middle.station.data.service.alarm.IScreenUserCarmeraConfigTimeService;
import com.wejoy.video.middle.station.data.util.WJAssert;
import com.wejoy.video.middle.station.data.vo.RespJSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.ArrayList;

/**
 * 用户大屏监控记忆配置 
 *
 * @author miracle_j
 * @date 2025年03月28日 18:01:33
 */
@RestController
@RequestMapping("/alarm/screenUserCarmeraConfigTime")
public class ScreenUserCarmeraConfigTimeController extends BaseController {

    @Autowired
    private IScreenUserCarmeraConfigTimeService screenUserCarmeraConfigTimeService;

    /**
     * 保存或更新
     *
     * @param screenUserCarmeraConfigTimeReq screenUserCarmeraConfigTimeReq
     * @return RespJSON
     */
    @PostMapping("/save")
    public RespJSON save(@RequestBody ScreenUserCarmeraConfigTime screenUserCarmeraConfigTimeReq, @SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) {
        ScreenUserCarmeraConfigTime oneByPointId = screenUserCarmeraConfigTimeService.getOneByPointId(screenUserCarmeraConfigTimeReq.getPointId());
        if(oneByPointId!=null){
            screenUserCarmeraConfigTimeReq.setId(oneByPointId.getId());
        }
        screenUserCarmeraConfigTimeReq.setUserId(loginSysUser.getId());
        screenUserCarmeraConfigTimeService.save(screenUserCarmeraConfigTimeReq, loginSysUser.getUserName());
        return RespJSON.success();
    }

    /**
     * 分页查询
     *
     * @param screenUserCarmeraConfigTimeReq screenUserCarmeraConfigTimeReq
     * @return RespJSON
     */
    @PostMapping("/getList")
    public RespJSON getList(@RequestBody ScreenUserCarmeraConfigTime screenUserCarmeraConfigTimeReq,@SessionAttribute(CurrentUserUtils.SYSTEM_USER) SysUser loginSysUser) {
        screenUserCarmeraConfigTimeReq.setUserId(loginSysUser.getId());
        return RespJSON.success(screenUserCarmeraConfigTimeService.getList(screenUserCarmeraConfigTimeReq));
    }

    /**
     * 主键查询
     *
     * @param id id
     * @return RespJSON
     */
    @RequestMapping("/getOneById")
    public RespJSON getOneById(Long id) {
        return RespJSON.success(screenUserCarmeraConfigTimeService.getOneById(id));
    }

    /**
    * 审核
    *
    * @param id id
    * @return RespJSON
    */
    @PostMapping("/audit")
    @ResponseBody
        public RespJSON audit(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER)SysUser loginSysUser) {
        WJAssert.notNull(id, "ID 不合法");
        screenUserCarmeraConfigTimeService.audit(id, loginSysUser.getUserName());
        return RespJSON.success();
    }

    /**
    * 取消审核
    *
    * @param id id
    * @return RespJSON
    */
    @PostMapping("/unaudit")
    @ResponseBody
        public RespJSON unaudit(Long id, @SessionAttribute(CurrentUserUtils.SYSTEM_USER)SysUser loginSysUser) {
        WJAssert.notNull(id, "ID 不合法");
        screenUserCarmeraConfigTimeService.unaudit(id, loginSysUser.getUserName());
        return RespJSON.success();
    }

}
